$(function () {
    $.ajax({
        url: bignews.user_detail,
        headers: { Authorization: localStorage.getItem('name') },
        success: function (src) {
            console.log(src)
            $('.common_con').html(`     <form class="form-horizontal article_form" id="form">
            <div class="form-group">
                <label for="inputEmail1" class="col-sm-2 control-label">用户名称：</label>
                <div class="col-sm-4">
                    <input type="text" name="username" class="form-control username" id="inputEmail1" value="${src.data.username}">
                </div>
            </div>
            <div class="form-group">
                <label for="inputEmail2" class="col-sm-2 control-label">昵称：</label>
                <div class="col-sm-4">
                    <input type="text" name="nickname" class="form-control nickname"  id="inputEmail2" value="${src.data.nickname}">
                </div>
            </div>
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">邮箱：</label>
                <div class="col-sm-4">
                    <input type="text" name="email" class="form-control email" id="inputEmail3" value="${src.data.email}">
                </div>
            </div>
    
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">用户图标：</label>
                <div class="col-sm-10">
                    <img src="${src.data.userPic}" alt="" class="user_pic">
                    <input style="display: block" name="userPic" type="file" id="exampleInputFile">
                    <!-- 给label标签的for属性赋值,值是input标签的id,那这样的话点击label就相当于点击了input -->
                    <br>
                    <label for="exampleInputFile">
                        <img src="./images/uploads_icon.jpg" style="height: 50px;" alt="">
                    </label>
                </div>
            </div>
    
            <div class="form-group">
                <label for="inputEmail4" class="col-sm-2 control-label">密码：</label>
                <div class="col-sm-4">
                    <input type="password" name="password" class="form-control password" id="inputEmail4"
                        value="${src.data.password}">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-success btn-edit">修改</button>
                </div>
            </div>
        </form>`)
        }
    })
    $('.common_con').on('click', '.btn-edit', function () {
        let formdata = new FormData($('#form')[0])
        console.log(formdata)
        $.ajax({
            url: bignews.user_edit,
            type: 'post',
            data: formdata,
            processData: false,
            contentType: false,
            headers: { Authorization: localStorage.getItem('name') },
            success: function (src) {
                console.log(src);
            }
        })
    })
    $('.common_con').on('change', '#exampleInputFile', function () {
        let myfile = this.files[0]
        let myurl = URL.createObjectURL(myfile)
        $('.user_pic').prop('src', myurl)
    })
})